package cn.exrick.xboot.modules.callApi;


import cn.exrick.xboot.common.jiuqiCommon.callAPIUtil.CallSMSservice;
import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.modules.backlogOrFull.entity.BacklogOrFull;
import cn.exrick.xboot.modules.backlogOrFull.service.IBacklogOrFullService;
import cn.exrick.xboot.modules.callApi.entity.SMS;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Date;

@Slf4j
@RestController
@Api(description = "短信平台调用")
@RequestMapping("/callSMS")
public class callSMS {

    @Autowired
    private CallSMSservice callSMSservice;


public void test(){
    CallSMSservice callSMSservice=new CallSMSservice();
    SMS sms=new SMS();
    sms.setDESTADDR("15145288819");
    sms.setMESSAGECONTENT("短信测试内容");
    boolean b = callSMSservice.sendSMS(sms);
    System.out.println("调用短信接口："+b);
}

    public static void main(String[] args) throws Exception {

      /*  // 1. 注册驱动
        // 使用java.sql.DriverManager类的静态方法registerDriver(Driver driver)
        // Driver是一个接口,参数传递:MySQL驱动程序的实现类
        // DriverManager.registerDriver(new Driver());
        // 查看驱动类源码,注册两次驱动,浪费资源
        Class.forName("com.mysql.jdbc.Driver");

        // 2. 获得连接
        // uri:数据库地址 jdbc:mysql://连接主机ip:端口号//数据库名字
        //String url = "jdbc:mysql://192.168.168.168:3306/dbadapter?useUnicode=true&characterEncoding=utf-8";
        String url = "jdbc:mysql://10.2.24.14:3306/dbadapter?useUnicode=true&characterEncoding=utf-8";
        // static Connection getConnection(String url, String user, String password)
        // 返回值是java.sql.Connection接口的实现类,在MySQL驱动程序中
       // Connection conn = DriverManager.getConnection(url, "masdb", "QAZwsx!@#123");
        Connection conn = DriverManager.getConnection(url, "root", "123456");
        System.out.println(conn);// com.mysql.jdbc.JDBC4Connection@10d1f30
        // 3. 获得语句执行平台,通过数据库连接对象,获取到SQL语句的执行者对象
        //conn对象,调用方法 Statement createStatement() 获取Statement对象,将SQL语句发送到数据库
        //返回的是Statement接口的实现类对象,在MySQL驱动程序中
        Statement stat = conn.createStatement();
        System.out.println(stat);//com.mysql.jdbc.StatementImpl@137bc9
        // 4. 执行sql语句
        //通过执行者对象调用方法执行SQL语句,获取结果
        //        //int executeUpdate(String sql)  执行数据库中的SQL语句,仅限于insert,update,delete
        //        //返回值int,操作成功数据库的行数


        StringBuffer content= new StringBuffer("陈希：路桥测试短信：验证码为123456");

        String SMSContent=null;
        try {
             SMSContent=new String(content.toString().getBytes(),"utf8");
            System.out.println(SMSContent);
        } catch (Exception e) {

            e.printStackTrace();
        }

        String  sql="Insert into sms_outbox  (sismsid, extcode, destaddr, messagecontent, \n" +
                "reqdeliveryreport,msgfmt,sendmethod,requesttime,applicationid)VALUES  \n" +
                "('89a72159-e267-3364-8e98-6430d74e631e', '16', '18670011860',  ' " +content.toString()+  " ', 1, 15, 0, '2019-09-19 17:06:53', 'smssend')";

        int row = stat.executeUpdate(sql);
        System.out.println(row);
        // 5. 释放资源
        stat.close();
        conn.close();*/

        callSMS  c=new callSMS();
        c.test();
    }

}
